package com.zeta.eduservice.utils.word;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.apache.poi.POIXMLDocument;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.model.types.PAPAbstractType;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.xwpf.usermodel.Document;
import org.apache.poi.xwpf.usermodel.ParagraphAlignment;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFPicture;
import org.apache.poi.xwpf.usermodel.XWPFRun;
import org.apache.poi.xwpf.usermodel.XWPFTable;
import org.apache.poi.xwpf.usermodel.XWPFTableCell;
import org.apache.poi.xwpf.usermodel.XWPFTableRow;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBody;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDocument1;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSectPr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblPr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblWidth;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTcBorders;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTcPr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBorder;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STJc;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STVerticalJc;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.Element;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Phrase;
import com.zeta.eduservice.entity.question.EduQuestionChoice;
import com.zeta.eduservice.entity.question.EduQuestionTypeSys;
import com.zeta.eduservice.entity.vo.PaperAndQuestionTypeSysVo;
import com.zeta.eduservice.entity.vo.PaperListVo;
import com.zeta.eduservice.entity.vo.QuestionChoiceVo;
import com.zeta.eduservice.entity.vo.QuestionQuery;
import com.zeta.eduservice.entity.vo.questionVo;
import com.zeta.eduservice.entity.vo.front.ChapterCourseDetialVo;
import com.zeta.eduservice.entity.vo.front.ChoiceVo;
import com.zeta.eduservice.entity.vo.front.PdfQuestionVo;
import com.zeta.eduservice.entity.vo.front.QuestionCreateInfo;
import com.zeta.eduservice.entity.vo.front.front.PaperInfoVo;
import com.zeta.eduservice.mapper.EduQuestionChoiceMapper;
import com.zeta.eduservice.mapper.EduQuestionMapper;
import com.zeta.eduservice.service.EduPaperService;
import com.zeta.eduservice.service.EduQuestionChoiceService;
import com.zeta.eduservice.service.EduQuestionService;
import com.zeta.eduservice.service.EduQuestionTypeSysService;

@Component
public class Load {
	@Autowired
	private EduQuestionService questionService;
	@Autowired
	private EduQuestionChoiceService choiceService;
	@Autowired
	private EduPaperService paperService;
	
	@Autowired
	WordCreateUtils wordUtils;
	@Autowired
	EduQuestionTypeSysService eduQuestiontypeService;

	@Autowired
	EduQuestionChoiceMapper questionChoiceMapper;
	@Autowired
	EduQuestionMapper questionMapper;

	//////////////////////////////////////////////////////////////////////////////////////
	public List<EduQuestionChoice> getQuestionByChoice(int diff, int num, List<ChapterCourseDetialVo> chapterList,
			PaperInfoVo paperInfo) {
		List<EduQuestionChoice> rand = new ArrayList<EduQuestionChoice>();
		int numchap = 0;
		Iterator<ChapterCourseDetialVo> iter = chapterList.iterator();
		while (iter.hasNext()) {
			ChapterCourseDetialVo z = iter.next();
			if (z.getType().equals("选择") && paperInfo.getChapterNumber() > numchap) {
				rand.addAll(questionChoiceMapper.getByRandomDetial(z.getDifficulty(), z.getNumber(), z.getId()));
				iter.remove();
				numchap++;

			}
			if (numchap == paperInfo.getChapterNumber()) {
				numchap = 0;
				break;
			}
		}
		return rand;
	}

	public List<EduQuestionChoice> getQuestionByChoice(int diff, int num) {
		List<EduQuestionChoice> rand = questionChoiceMapper.getByRandom(diff, num);
		return rand;

	}

	List<PdfQuestionVo> getQuestionByType(String type, int diff, int number) {
		List<PdfQuestionVo> byRand = questionMapper.getByRand(type, diff, number);
		return byRand;

	}

	List<PdfQuestionVo> getQuestionByType(String type, int diff, int number, List<ChapterCourseDetialVo> chapterList,
			PaperInfoVo paperInfo) {
		List<PdfQuestionVo> byRand = new ArrayList<PdfQuestionVo>();
		int numchap2 = 0;
		Iterator<ChapterCourseDetialVo> iter = chapterList.iterator();
		while (iter.hasNext()) {
			ChapterCourseDetialVo z = iter.next();
			if (z.getType().equals(type) && numchap2 < paperInfo.getChapterNumber()) {
				byRand.addAll(questionMapper.getByRandDetial(z.getType(), z.getDifficulty(), z.getNumber(), z.getId()));
				iter.remove();
				numchap2++;

			}
			if (numchap2 == paperInfo.getChapterNumber()) {
				numchap2 = 0;
				break;
			}
		}

		return byRand;

	}
//课程管理 试卷生成\

	


	//////////////////////////////////////////////////////////////////////////////////////
	

}
